//
//  HMUserCell.swift
//  HealthMonitoring
//
//  Created by 珠海正杰 on 2018/9/21.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import SwiftyJSON

class HMUserCell: HMTableViewCell {
    let title = UILabel()
    let icon = UIImageView()
    let img = UIImageView()
    let describe = UILabel()
//    var type = "describe"
    
    public enum DescribeType {
        case unknown
        case describe
        case image
    }
    
    override func setupViews(view: UIView) {
        view.addSubview(title)
        view.addSubview(icon)
        view.addSubview(img)
        view.addSubview(describe)
    
        title.centerYAlign(view: view, predicate: "0")
        title.leadingAlign(view: view, predicate: "10")
        title.text = "头像"
       
        // 箭头
        img.centerYAlign(view: view)
        img.trailingAlign(view: view, predicate: "-10")
        img.widthConstrain(predicate: "20")
        img.heightConstrain(predicate: "20")
        img.imgName(name: "ringht.png")
        
        // 头像
        icon.centerYAlign(view: view)
        icon.img(url: "")
        icon.trailingHorizontally(view: img, predicate: "-10")
        icon.heightConstrain(predicate: "66")
        icon.widthConstrain(predicate: "66")
        icon.layer.cornerRadius = (66/2)
        icon.layer.masksToBounds = true
        icon.backgroundColor = .red
        
        
        // 描述
        describe.centerYAlign(view: view)
        describe.trailingHorizontally(view: img, predicate: "-10")
//        icon.heightConstrain(predicate: "66")
//        describe.widthConstrain(predicate: "50")
        
    }
    
    
    override func setJson(json: JSON) {
//        let newJson = json[]
        let _t = json["title"].stringValue
        let _i = json["icon"].stringValue
        let _d = json["describe"].stringValue
        let isHiddenImg = json["hiddenImg"].boolValue
        
        title.text = _t
        if _i.count > 0 {
           icon.isHidden = false
           describe.isHidden = true
           icon.img(url: _i)
        }else {
           icon.isHidden = true
           describe.isHidden = false
           describe.text = _d
        }
        
        if !isHiddenImg {
            img.isHidden = isHiddenImg
        }else {
            img.isHidden = isHiddenImg
        }
        
        
        
        
        
    }
    
    
}
